/*
 * @(#)JsonUtil.java
 *
 * Copyright 2012 by ShenY BIS, All rights reserved.
 */

package com.bis.log;

import org.apache.log4j.Appender;
import org.apache.log4j.FileAppender;
import org.apache.log4j.Logger;

import com.bis.framework.security.context.SecurityContextInfo;
import com.bis.framework.util.common.COConstants;
import com.bis.framework.util.common.SystemConfig;
import com.bis.framework.util.common.TextUtil;

/**
 * BLogger
 * 
 * @author BIS 2012-12-24
 */
public class BLogger
{

    /**
     * LOG日志
     */
    protected static Logger logger  = Logger.getLogger(BLogger.class);

    /**
     * Log日志路径
     */
    protected static String LOGPATH = "";

    /**
     * 写客户端日志 Error级别
     * 
     * @param log
     */
    public static void info(String log)
    {
        //日志保存路径
        StringBuffer objSB = new StringBuffer();
        //业务日志名称
        String strBusinessLogName = SystemConfig.getValue(COConstants.BUSINESS_LOG_NAME, "BFILE");
        //日志信息
        Appender appender = Logger.getLogger(BLogger.class).getAppender(strBusinessLogName);
        if (null != SecurityContextInfo.getSessionEntity())
        {
            //重新设置日志保存路径
            if (appender instanceof FileAppender && TextUtil.isEmpty(LOGPATH))
            {
                //取得日志保存文件信息
                FileAppender fileAppender = (FileAppender) appender;
                //取得日志路径
                if (TextUtil.isEmpty(LOGPATH))
                {
                    LOGPATH = fileAppender.getFile();
                }
                //设置文件
                fileAppender.setFile(objSB.append(LOGPATH).append(SecurityContextInfo.getSessionEntity().getWelcomeUrl()).append("/log.txt").toString());
                //刷新日志保存路径
                fileAppender.activateOptions();
            }
            logger.info("[" + SecurityContextInfo.getSessionEntity().getWelcomeUrl() + "] - " + log);
        }
    }
}
